package bairui.international.console.web.controller.delicate.category;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lianjing.sh.spring.web.controller.base.action.Action;
import com.lianjing.sh.spring.web.controller.enhance.output.FomatOutput;
import com.lianjing.sh.validate.spring.exception.ValidateObjectException;
import com.sh_lianjing.util.Util_BeanCopyByDeclaredProperties;

import bairui.international.model.domain.jpa.TB_ProductCategory;
import bairui.international.service.Service_ProductCategory;

/**
 *
 * 添加
 *
 * @generated
 * 
 * @see STest_C_Delicate_Category_Add_Add 测试
 *
 */
@Controller
public class C_Delicate_Category_Add_Add
 extends SC_Delicate_Category_Add_Add 
{
	
	@Autowired private Service_ProductCategory service_ProductCategory;
	
	/**
	 * 添加
	 */
	@Action(Add.class)
	@PostMapping(Add.RequestMappingValue)
	public @FomatOutput @ResponseBody Object add(
		@Valid Add.InputModel input,
		@PathVariable(name=Add.PathVariableName.ParentId) Long parentId
	) throws Exception {
		if(null == parentId){
			throw new ValidateObjectException("object", "", "业务需要顶级分类不能添加" );
		}
		TB_ProductCategory bean = Util_BeanCopyByDeclaredProperties.copyProperties(input, new TB_ProductCategory());
		bean = service_ProductCategory.save(bean, parentId);
		//
		return null;
	}
	

}
